from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel, Field


class CustomerLoginRequest(BaseModel):
    code: str


class CreateCustomerRequest(BaseModel):
    created_on: Optional[datetime] = None
    created_by: Optional[int] = None
    openid: str
    level: Optional[int] = 1
    nickname: Optional[str] = Field(default_factory=lambda: "用户" + str(int(datetime.now().timestamp())))
    avatar: Optional[str] = None
    phone: Optional[str] = None
    gender: Optional[int] = -1


class CustomerModel(BaseModel):
    id: int
    created_on: Optional[datetime] = None
    created_by: Optional[int] = None
    updated_on: Optional[datetime] = None
    updated_by: Optional[int] = None
    status: Optional[int] = None
    openid: str
    nickname: str
    level: int
    avatar: Optional[str] = None
    phone: Optional[str] = None
    gender: Optional[int] = -1
    last_login_time: Optional[datetime] = None

    class Config:
        from_attributes = True


class CustomerPagination(BaseModel):
    page: int
    page_size: int
    total: int
    data: List[CustomerModel]


class CustomerLoginResponse(CustomerModel):
    token: str
    expires: Optional[int] = None


class CustomerRefreshTokenResponse(CustomerLoginResponse):
    pass


class UpdateCustomerInfoRequest(BaseModel):
    id: Optional[int] = None
    updated_on: Optional[datetime] = None
    updated_by: Optional[int] = None
    nickname: Optional[str] = None
    avatar: Optional[str] = None
    phone: Optional[str] = None
    gender: Optional[int] = None


class UpdateCustomerInfoResponse(BaseModel):
    id: int
    nickname: Optional[str] = None
    avatar: Optional[str] = None
    phone: Optional[str] = None
    gender: Optional[int] = None
